package itsm.isperp.module.controller.wechat.mp;

import itsm.isperp.framework.core.context.ContextHolder;
import itsm.isperp.module.entity.app.AppConfig;
import itsm.isperp.module.service.app.AppConfigService;

import java.util.List;

import javax.servlet.http.HttpServletRequest;

import me.chanjar.weixin.mp.api.WxMpService;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.servlet.ModelAndView;

/**
 * 微信用户组管理
 * 
 * 
 * @author lizx
 * @date 2014-11-4
 * @since 1.0
 * 
 */
@Controller
@RequestMapping("wechat/mp/config")
public class WechatMpConfigController {

	@Autowired
	WxMpService wxMpService;

	@RequestMapping(value = { "", "manage" })
	public ModelAndView manage(HttpServletRequest req) {
		ModelAndView mv = new ModelAndView("wechat/mp/config");

		AppConfigService appConfigService = ContextHolder
				.getSpringBean("appConfigService");

		List<AppConfig> list = appConfigService.findAll();
		for (AppConfig appConfig : list) {
			mv.addObject(appConfig.getItemKey(), appConfig.getItemValue());
		}

		try {
			 
			mv.addObject("wechatMpAccessToken", wxMpService.getAccessToken());
		} catch (Exception e) {
			mv.addObject("wechatMpToken", e.getMessage());
		}
		return mv;
	}
}
